Skip to content

fix(backend): Fix getToken() from getAuth() return value in v5 - #2539

Merged
dimkl merged 1 commit into
mainfrom
sdk-1192-get-token
Jan 11, 2024
Merged

fix(backend): Fix getToken() from getAuth() return value in v5#2539
dimkl merged 1 commit into
mainfrom
sdk-1192-get-token

Conversation

@dimkl

@dimkl dimkl commented Jan 10, 2024

Copy link
Copy Markdown
Contributor

Description

Change SessionApi.getToken() to return consistent { data, errors } return value and fix the getToken() from requestState to have the same return behavior as v4 (return Promise or throw error).
This change fixes issues with getToken() in @clerk/nextjs / @clerk/remix / @clerk/fastify / @clerk/sdk-node / gatsby-plugin-clerk:

Example:

import { getAuth } from '@clerk/nextjs/server';

const { getToken } = await getAuth(...);
const jwtString = await getToken(...);

The change in SessionApi.getToken() return value is a breaking change, to keep the existing behavior use the following:

import { ClerkAPIResponseError } from '@clerk/shared/error';

const response = await clerkClient.sessions.getToken(...);

if (response.errors) {
    const { status, statusText, clerkTraceId } = response;
    const error = new ClerkAPIResponseError(statusText || '', {
        data: [],
        status: Number(status || ''),
        clerkTraceId,
    });
    error.errors = response.errors;

    throw error;
}

// the value of the v4 `clerkClient.sessions.getToken(...)`
const jwtString = response.data.jwt;

Checklist

  • npm test runs as expected.
  • npm run build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Packages affected

  • @clerk/backend
  • @clerk/chrome-extension
  • @clerk/clerk-js
  • @clerk/clerk-expo
  • @clerk/fastify
  • gatsby-plugin-clerk
  • @clerk/localizations
  • @clerk/nextjs
  • @clerk/clerk-react
  • @clerk/remix
  • @clerk/clerk-sdk-node
  • @clerk/shared
  • @clerk/themes
  • @clerk/types
  • build/tooling/chore

@dimkl dimkl added bug Something isn't working v5-release labels Jan 10, 2024
@dimkl dimkl self-assigned this Jan 10, 2024
@changeset-bot

changeset-bot Bot commented Jan 10, 2024

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 37fac81

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@clerk/backend Major
@clerk/fastify Patch
gatsby-plugin-clerk Patch
@clerk/nextjs Patch
@clerk/remix Patch
@clerk/clerk-sdk-node Patch
@clerk/elements Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dimkl
dimkl force-pushed the sdk-1192-get-token branch from fa82747 to e2d6e6b Compare January 10, 2024 15:40
@dimkl
dimkl force-pushed the sdk-1192-get-token branch 2 times, most recently from 404043b to 60ba984 Compare January 10, 2024 16:33
@dimkl

dimkl commented Jan 10, 2024

Copy link
Copy Markdown
Contributor Author

!snapshot

@dimkl

dimkl commented Jan 10, 2024

Copy link
Copy Markdown
Contributor Author

!snapshot

@clerk-cookie

Copy link
Copy Markdown
Collaborator

Hey @dimkl - the snapshot version command generated the following package versions:

Package Version
@clerk/backend 1.0.1-snapshot.v60ba984
@clerk/chrome-extension 1.0.1-snapshot.v60ba984
@clerk/clerk-js 5.0.1-snapshot.v60ba984
@clerk/elements 0.0.3-snapshot.v60ba984
@clerk/clerk-expo 1.0.1-snapshot.v60ba984
@clerk/fastify 1.0.1-snapshot.v60ba984
gatsby-plugin-clerk 5.0.1-snapshot.v60ba984
@clerk/localizations 2.0.1-snapshot.v60ba984
@clerk/nextjs 5.0.1-snapshot.v60ba984
@clerk/clerk-react 5.0.1-snapshot.v60ba984
@clerk/remix 4.0.1-snapshot.v60ba984
@clerk/clerk-sdk-node 5.0.1-snapshot.v60ba984
@clerk/shared 2.0.1-snapshot.v60ba984
@clerk/themes 2.0.1-snapshot.v60ba984
@clerk/types 4.0.1-snapshot.v60ba984

Tip: Use the snippet copy button below to quickly install the required packages.
@clerk/backend

npm i @clerk/backend@1.0.1-snapshot.v60ba984 --save-exact

@clerk/chrome-extension

npm i @clerk/chrome-extension@1.0.1-snapshot.v60ba984 --save-exact

@clerk/clerk-js

npm i @clerk/clerk-js@5.0.1-snapshot.v60ba984 --save-exact

@clerk/elements

npm i @clerk/elements@0.0.3-snapshot.v60ba984 --save-exact

@clerk/clerk-expo

npm i @clerk/clerk-expo@1.0.1-snapshot.v60ba984 --save-exact

@clerk/fastify

npm i @clerk/fastify@1.0.1-snapshot.v60ba984 --save-exact

gatsby-plugin-clerk

npm i gatsby-plugin-clerk@5.0.1-snapshot.v60ba984 --save-exact

@clerk/localizations

npm i @clerk/localizations@2.0.1-snapshot.v60ba984 --save-exact

@clerk/nextjs

npm i @clerk/nextjs@5.0.1-snapshot.v60ba984 --save-exact

@clerk/clerk-react

npm i @clerk/clerk-react@5.0.1-snapshot.v60ba984 --save-exact

@clerk/remix

npm i @clerk/remix@4.0.1-snapshot.v60ba984 --save-exact

@clerk/clerk-sdk-node

npm i @clerk/clerk-sdk-node@5.0.1-snapshot.v60ba984 --save-exact

@clerk/shared

npm i @clerk/shared@2.0.1-snapshot.v60ba984 --save-exact

@clerk/themes

npm i @clerk/themes@2.0.1-snapshot.v60ba984 --save-exact

@clerk/types

npm i @clerk/types@4.0.1-snapshot.v60ba984 --save-exact

@dimkl
dimkl force-pushed the sdk-1192-get-token branch 2 times, most recently from 2f08925 to 7ffbc66 Compare January 10, 2024 18:41
@dimkl
dimkl force-pushed the sdk-1192-get-token branch from 7ffbc66 to 37fac81 Compare January 11, 2024 09:35
@SokratisVidros

Copy link
Copy Markdown
Contributor

We will proceed with this change in V6.

@dimkl
dimkl added this pull request to the merge queue Jan 11, 2024
Merged via the queue into main with commit 799abc2 Jan 11, 2024
@dimkl
dimkl deleted the sdk-1192-get-token branch January 11, 2024 14:31
dimkl added a commit to clerk/clerk-docs that referenced this pull request Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants